﻿using Genius.Brain.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Genius.Brain.Shared.BO;
using Genius.Brain.Shared.Locator;
using Genius.Brain.Shared.Strategy;

namespace Modules.SmallTalk.Impl
{
    class GeniusModule : IGeniusModule
    {
        private IDictionary<string, ILanguageConstructorStrategy> _languageConstructorStrategy;
        private ITextFormaterStrategy _textFormaterStrategy;
        private ITextParserStrategy _textParserStrategy;

        public GeniusModule()
        {

            _languageConstructorStrategy = new Dictionary<string, ILanguageConstructorStrategy>();
            _languageConstructorStrategy["es"] = BrainLocator.GetLanguageConstructorStrategy("es");
            _languageConstructorStrategy["de"] = BrainLocator.GetLanguageConstructorStrategy("de");
            _languageConstructorStrategy["en"] = BrainLocator.GetLanguageConstructorStrategy("en");

            string[] files = new string[] { @"Data\smalltalk_de.json" , @"Data\smalltalk_en.json" , @"Data\smalltalk_es.json" };
            _textParserStrategy = BrainLocator.GetTextParserStrategy(files); 
            _textFormaterStrategy = BrainLocator.GetTextFormaterStrategy(files); 
        }
        public GeniusModuleState RecvMessage(IDialogContext context, IMessage message, IMessage response)
        {
            var Text = _textParserStrategy.Parse(message.Text);
            if (Text.Token.StartsWith("#ASKME"))
            {
                var text = BrainLocator.GetText(Text.Token + "CONFIRM", Text.Language);
                text.Params["name"] = context.Name;
                text.Params["days"] = Convert.ToInt32((DateTime.Now - new DateTime(2016, 03, 05)).TotalDays).ToString();
                text.Params["inventors"] = _languageConstructorStrategy[Text.Language].Concat(context.Inventors);
                response.Text = _textFormaterStrategy.Format(text);
                return GeniusModuleState.Once;
            }
            return GeniusModuleState.None;
        }
    }
}
